package com.ashin;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;

public class Test {

    private static final String ybUrl = "https://open.fjylbz.gov.cn";

    public static void main(String[] args) throws Exception {
        SzDdjsUtil szDdjsUtil=new SzDdjsUtil();
        Map<String, Object> postJsonM = szDdjsUtil.postJsonM(ybUrl, getTokenParams());
        System.out.println(postJsonM);
              
        
//        CloseableHttpClient httpclient = HttpClients.createDefault();
//
//        HttpPost httpPost = new HttpPost(ybUrl);
//        Map<String, Object> tokenParams = getTokenParams();
//
//        final String jsonString = JSON.toJSONString(tokenParams);
//        System.out.println("请求参数" + jsonString);
//        StringEntity entity = new StringEntity(jsonString);
//        httpPost.setEntity(entity);
//
//        CloseableHttpResponse response2 = httpclient.execute(httpPost);
//
//        try {
//            System.out.println(response2.getStatusLine());
//
//            HttpEntity entity2 = response2.getEntity();
//
//            System.out.println(EntityUtils.toString(entity2, "utf-8"));
//
//            EntityUtils.consume(entity2);
//
//        } finally {
//            response2.close();
//        }

    }

    public static Map<String, Object> getTokenParams() {
        Map<String, Object> dataParams = new HashMap<String, Object>();
        dataParams.put("appid", "e8843bbdb97b4d13");
        dataParams.put("appsecret", "a0hPejZPOWV0ZEg0K2dxNlBLTTlMY21nS0x5eVRWZmpBRVFvZXNEaXJZZz0=");
        dataParams.put("grant_type", "client_credentials");

        //
        // fzTokenAppid=e8843bbdb97b4d13
        // fzTtokenAppsecret=a0hPejZPOWV0ZEg0K2dxNlBLTTlMY21nS0x5eVRWZmpBRVFvZXNEaXJZZz0=

        Map<String, Object> allParams = new HashMap<String, Object>();
        allParams.put("data", dataParams);
        allParams.put("funid", "N00.00.00.01");
        allParams.put("sign", "9A0A8659F005D6984697E2CA0A9CF3B7");

        return allParams;
    }

}
